//
//  STMemorailTableCell.swift
//  SlowTrajectory
//
//  Created by iOS-Czz on 2023/10/23.
//

import UIKit

class STMemorailTableCell: UITableViewCell {
    @IBOutlet var distanceLabel: UILabel!
    
    @IBOutlet var nextLabel: UILabel!
    @IBOutlet var dateLabel: UILabel!
    @IBOutlet var wayLabel: UILabel!
    @IBOutlet var nameLabel: UILabel!
    override func awakeFromNib() {
        super.awakeFromNib()
    }
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    override func layoutIfNeeded() {
        super.layoutIfNeeded()
        self.distanceLabel.addDashedBorder(color: .black, lineWidth: 1, cornerRadius: 15)
        
    }
    var model: STMemorailModel? {
        didSet {
            self.nameLabel.text = model?.name
            self.dateLabel.text = "事件日期: " + model!.date
            let eventDay = model?.date.substring(from:4)
            let next = Date().toString(format: "yyyy") + eventDay!
            
            self.wayLabel.text = getWay(model!.way)
            let (nextReminderDate, daysUntilReminder) = String.calculateNextReminderDate(from: next, withWay: self.model!.way)
            self.nextLabel.text = "下次纪念: " + nextReminderDate
            self.distanceLabel.text = "还有\(daysUntilReminder)天"

        }
    }
    func getWay(_ way:Int) -> String {
        let ways = ["年计算","月计算","周计算"]
        return ways[way]
    }
    
}
